<?php
namespace Purse\Model;
use Think\Model;
class CrowdfundDetailModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_crowdfund_detail'; 
	
	
	public function getCrowdfundList($fundid){
		$map = array();
		if(!empty($fundid)){
			$map['qyx_crowdfund_detail.fundid'] = $fundid;
		}
		
		$fields = array('qyx_crowdfund_detail.id','qyx_crowdfund_detail.fundid','qyx_crowdfund_detail.custid',
						'qyx_crowdfund_detail.amount','qyx_crowdfund_detail.createtime','qyx_crowdfund_detail.updatetime');
	
		$data['sortField'] = "qyx_crowdfund_detail.amount";
		$data['sortOrder'] = "desc";
	
		$result = $this->join('qyx_crowdfund on qyx_crowdfund_detail.fundid = qyx_crowdfund.fundid')->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->select();
	
		return $result;
	}
	
	
	public function getTotal($fundid){
		$map = array();
		if(!empty($fundid)){
			$map['qyx_crowdfund_detail.fundid'] = $fundid;
		}
		
		$result = $this->join('qyx_crowdfund on qyx_crowdfund_detail.fundid = qyx_crowdfund.fundid')->field('sum(qyx_crowdfund_detail.amount) as fundamount')->where($map)->find();
		
		return $result;
	}
	
	public function addCrowdfundDetail($data){
		$result = $this->add($data);
		return $result;
	}
}


